<?php

namespace app\models\search;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\CrmHwzxHistory;

/**
 * CrmHwzxHistorySearch represents the model behind the search form of `app\models\CrmHwzxHistory`.
 */
class CrmHwzxHistorySearch extends CrmHwzxHistory
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'gsid', 'wcj', 'operatorUserid'], 'integer'],
            [['ldhm', 'mtly', 'bjhm', 'zryy', 'zxcp', 'gtnr', 'khmc', 'khxb', 'nld', 'zy', 'sjhm', 'jtdh', 'gzdh', 'zhld', 'sfcsqx', 'xxdz', 'yzbm', 'khzl', 'khly', 'khxq', 'hydj', 'khbz', 'zzjxsj', 'gxsj', 'dhfsj', 'xgfpsj', 'khjf', 'operatorUsername', 'operatorContent', 'operatorRIp', 'gnk', 'operatorLIp', 'operatorYggh', 'operatorZuoxi'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CrmHwzxHistory::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'gsid' => $this->gsid,
            'wcj' => $this->wcj,
            'operatorUserid' => $this->operatorUserid,
        ]);
        if (!empty($this->gxsj)){
            if (count($this->gxsj)>1){
                $query->andFilterWhere(['between', 'gxsj',$this->gxsj[0] ,$this->gxsj[1]]);
            }
        }
        $query->andFilterWhere(['like', 'ldhm', $this->ldhm])
            ->andFilterWhere(['like', 'mtly', $this->mtly])
            ->andFilterWhere(['like', 'bjhm', $this->bjhm])
            ->andFilterWhere(['like', 'zryy', $this->zryy])
            ->andFilterWhere(['like', 'zxcp', $this->zxcp])
            ->andFilterWhere(['like', 'gtnr', $this->gtnr])
            ->andFilterWhere(['like', 'khmc', $this->khmc])
            ->andFilterWhere(['like', 'khxb', $this->khxb])
            ->andFilterWhere(['like', 'nld', $this->nld])
            ->andFilterWhere(['like', 'zy', $this->zy])
            ->andFilterWhere(['like', 'sjhm', $this->sjhm])
            ->andFilterWhere(['like', 'jtdh', $this->jtdh])
            ->andFilterWhere(['like', 'gzdh', $this->gzdh])
            ->andFilterWhere(['like', 'zhld', $this->zhld])
            ->andFilterWhere(['like', 'sfcsqx', $this->sfcsqx])
            ->andFilterWhere(['like', 'xxdz', $this->xxdz])
            ->andFilterWhere(['like', 'yzbm', $this->yzbm])
            ->andFilterWhere(['like', 'khzl', $this->khzl])
            ->andFilterWhere(['like', 'khly', $this->khly])
            ->andFilterWhere(['like', 'khxq', $this->khxq])
            ->andFilterWhere(['like', 'hydj', $this->hydj])
            ->andFilterWhere(['like', 'khbz', $this->khbz])
            ->andFilterWhere(['like', 'zzjxsj', $this->zzjxsj])
            ->andFilterWhere(['like', 'dhfsj', $this->dhfsj])
            ->andFilterWhere(['like', 'xgfpsj', $this->xgfpsj])
            ->andFilterWhere(['like', 'khjf', $this->khjf])
            ->andFilterWhere(['like', 'operatorUsername', $this->operatorUsername])
            ->andFilterWhere(['like', 'operatorContent', $this->operatorContent])
            ->andFilterWhere(['like', 'operatorRIp', $this->operatorRIp])
            ->andFilterWhere(['like', 'gnk', $this->gnk])
            ->andFilterWhere(['like', 'operatorLIp', $this->operatorLIp])
            ->andFilterWhere(['like', 'operatorYggh', $this->operatorYggh]);

        return $dataProvider;
    }
}
